/**
 * 
 */
package org.bankabeule.ui.actions;

import org.bankabeule.core.ModelManager;
import org.bankabeule.ui.Activator;
import org.bankabeule.ui.utils.Logger;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

/**
 * @author sdudoit
 * 
 */
public class CloseAction extends AbstractAction {


	public CloseAction() {
		super();
		setText("&Close");
		setId(getClass().getCanonicalName());
		setImageDescriptor(Activator.getImageDescriptor("Close.gif"));
	}
	
	
	@Override
	public void run() {
		try {
			if (ModelManager.get().isDirty()) {
				boolean mustSave = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), 
						"Confirmation", "Do you want to save before closing ?");
				if (mustSave) {
					ModelManager.get().save();
				}
			}
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
			ModelManager.get().unload();
		} catch (Exception e) {
			Logger.log(e);
		}
	}

	
}
